﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Pcb.Common;
using Pcb.BLL;
using System.Data;

namespace Pcb.Web.admin.pcb
{
    public partial class option_list : Web.UI.ManagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ChkAdminLevel("pcb_optionset", DTEnums.ActionEnum.View.ToString()); //检查权限
                ShowInfo();
            }
        }

        #region 赋值操作=================================
        private void ShowInfo()
        {
            OptionBLL bll = new OptionBLL();
            int recordCount = 0;
            DataTable dt = new DataTable();

            #region 基础设置

            dt = bll.GetList(10, 1, "TypeName='基础设置'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "板费单价")
                    tbBF.Text = KeyValue;
                else if (KeyName == "工程费")
                    tbGCF.Text = KeyValue;
                else if (KeyName == "菲林费")
                    tbFLF.Text = KeyValue;
            }

            #endregion

            #region 板子层数
            dt = bll.GetList(10, 1, "TypeName='板子层数'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "1层板")
                    tbLayer1.Text = KeyValue;
                else if (KeyName == "2层板")
                    tbLayer2.Text = KeyValue;
                else if (KeyName == "3层板")
                    tbLayer3.Text = KeyValue;
                else if (KeyName == "6层板")
                    tbLayer6.Text = KeyValue;
            }
            #endregion

            #region 板子厚度

            dt = bll.GetList(10, 1, "TypeName='板子厚度'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "0.4")
                    tbBoardThickness04.Text = KeyValue;
                else if (KeyName == "0.6")
                    tbBoardThickness06.Text = KeyValue;
                else if (KeyName == "0.8")
                    tbBoardThickness08.Text = KeyValue;
                else if (KeyName == "1.0")
                    tbBoardThickness10.Text = KeyValue;
                else if (KeyName == "1.2")
                    tbBoardThickness12.Text = KeyValue;
                else if (KeyName == "1.6")
                    tbBoardThickness16.Text = KeyValue;
                else if (KeyName == "2.0")
                    tbBoardThickness20.Text = KeyValue;
            }

            #endregion

            #region 飞针测试

            dt = bll.GetList(10, 1, "TypeName='飞针测试'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "抽测试(免费AOI光学扫描+飞针抽测)")
                    tbTestType1.Text = KeyValue;
                else if (KeyName == "不测试")
                    tbTestType2.Text = KeyValue;
                else if (KeyName == "全部测试(样板及多层板免费测试)")
                    tbTestType3.Text = KeyValue;   
            }

            #endregion

            #region 焊盘喷镀

            dt = bll.GetList(10, 1, "TypeName='焊盘喷镀'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "有铅喷锡")
                    tbPlatingType1.Text = KeyValue;
                else if (KeyName == "无铅喷锡")
                    tbPlatingType2.Text = KeyValue;
                else if (KeyName == "沉金")
                    tbPlatingType3.Text = KeyValue;
            }

            #endregion

            #region 交货时间

            dt = bll.GetList(10, 1, "TypeName='交货时间'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "样板24小时加急")
                    tbDeliveryType1.Text = KeyValue;
                else if (KeyName == "样板48小时加急")
                    tbDeliveryType2.Text = KeyValue;
                else if (KeyName == "多层板48小时加急")
                    tbDeliveryType3.Text = KeyValue;
                else if (KeyName == "多层板72小时加急")
                    tbDeliveryType4.Text = KeyValue;
                else if (KeyName == "多层板96小时加急")
                    tbDeliveryType5.Text = KeyValue;
                else if (KeyName == "正常3-4天(样板)")
                    tbDeliveryType6.Text = KeyValue;
                else if (KeyName == "正常4-5天(样板)")
                    tbDeliveryType7.Text = KeyValue;
                else if (KeyName == "正常5-6天(样板)")
                    tbDeliveryType8.Text = KeyValue;
                else if (KeyName == "正常6-7天(小批量)")
                    tbDeliveryType9.Text = KeyValue;
                else if (KeyName == "正常7-8天(小批量)")
                    tbDeliveryType10.Text = KeyValue;              
            }
            
            #endregion

            #region 拼版款数

            dt = bll.GetList(10, 1, "TypeName='拼版款数'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "拼版款数")
                    tbPinBanNum.Text = KeyValue;             
            }

            #endregion

            #region 铜箔厚度

            dt = bll.GetList(10, 1, "TypeName='铜箔厚度'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "1/1oz")
                    tbCopperThickness1.Text = KeyValue;
                else if (KeyName == "2/2oz")
                    tbCopperThickness2.Text = KeyValue;    
            }

            #endregion

            #region 网络支付折扣

            dt = bll.GetList(20, 1, "TypeName='网络支付折扣'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "工程费")
                    tbPay1.Text = KeyValue;
                else if (KeyName == "拼版费")
                    tbPay2.Text = KeyValue;
                else if (KeyName == "板费")
                    tbPay3.Text = KeyValue;
                else if (KeyName == "菲林费")
                    tbPay4.Text = KeyValue;
                else if (KeyName == "税费")
                    tbPay5.Text = KeyValue;
                else if (KeyName == "喷镀费")
                    tbPay6.Text = KeyValue;
                else if (KeyName == "测试费")
                    tbPay7.Text = KeyValue;
                else if (KeyName == "加急费")
                    tbPay8.Text = KeyValue;
                else if (KeyName == "颜色费")
                    tbPay9.Text = KeyValue;
            }

            #endregion

            #region 需要发票

            dt = bll.GetList(10, 1, "TypeName='需要发票'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "不需要")
                    tbBill1.Text = KeyValue;
                else if (KeyName == "普通发票")
                    tbBill2.Text = KeyValue;
                else if (KeyName == "增值税发票")
                    tbBill3.Text = KeyValue;
            }

            #endregion

            #region 字符颜色

            dt = bll.GetList(10, 1, "TypeName='字符颜色'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "白色")
                    tbFontColor1.Text = KeyValue;
                else if (KeyName == "黑色")
                    tbFontColor2.Text = KeyValue;               
            }

            #endregion

            #region 阻焊覆盖

            dt = bll.GetList(10, 1, "TypeName='阻焊覆盖'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "过孔盖油")
                    tbZhfg1.Text = KeyValue;
                else if (KeyName == "过孔开窗")
                    tbZhfg2.Text = KeyValue;
            }

            #endregion

            #region 阻焊颜色

            dt = bll.GetList(10, 1, "TypeName='阻焊颜色'", "ID", out recordCount);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var KeyName = dt.Rows[i]["KeyName"].ToString();
                var KeyValue = dt.Rows[i]["KeyValue"].ToString();
                if (KeyName == "绿色")
                    tbSolderColor1.Text = KeyValue;
                else if (KeyName == "红色")
                    tbSolderColor2.Text = KeyValue;
                else if (KeyName == "黄色")
                    tbSolderColor3.Text = KeyValue;
                else if (KeyName == "蓝色")
                    tbSolderColor4.Text = KeyValue;
                else if (KeyName == "白色")
                    tbSolderColor5.Text = KeyValue;
                else if (KeyName == "黑色")
                    tbSolderColor6.Text = KeyValue;
            }

            #endregion

        }
        #endregion

        /// <summary>
        /// 保存配置信息
        /// </summary>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("pcb_optionset", DTEnums.ActionEnum.Edit.ToString()); //检查权限
            OptionBLL bll = new OptionBLL();

            //基础设置
            bll.UpdateField("typename='基础设置' and KeyName = '板费单价'", "keyvalue = '" + _Convert.ToFloat(tbBF.Text, 0) + "'");
            bll.UpdateField("typename='基础设置' and KeyName = '工程费'", "keyvalue = '" + _Convert.ToFloat(tbGCF.Text, 0) + "'");
            bll.UpdateField("typename='基础设置' and KeyName = '菲林费'", "keyvalue = '" + _Convert.ToFloat(tbFLF.Text, 0) + "'");

            //板子层数            
            bll.UpdateField("typename='板子层数' and KeyName = '1层板'", "keyvalue = '" + _Convert.ToFloat(tbLayer1.Text, 0) + "'");
            bll.UpdateField("typename='板子层数' and KeyName = '2层板'", "keyvalue = '" + _Convert.ToFloat(tbLayer2.Text, 0) + "'");
            bll.UpdateField("typename='板子层数' and KeyName = '3层板'", "keyvalue = '" + _Convert.ToFloat(tbLayer3.Text, 0) + "'");
            bll.UpdateField("typename='板子层数' and KeyName = '6层板'", "keyvalue = '" + _Convert.ToFloat(tbLayer6.Text, 0) + "'");

            //板子厚度
            bll.UpdateField("typename='板子厚度' and KeyName = '0.4'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness04.Text, 0) + "'");
            bll.UpdateField("typename='板子厚度' and KeyName = '0.6'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness06.Text, 0) + "'");
            bll.UpdateField("typename='板子厚度' and KeyName = '0.8'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness08.Text, 0) + "'");
            bll.UpdateField("typename='板子厚度' and KeyName = '1.0'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness10.Text, 0) + "'");
            bll.UpdateField("typename='板子厚度' and KeyName = '1.2'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness12.Text, 0) + "'");
            bll.UpdateField("typename='板子厚度' and KeyName = '1.6'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness16.Text, 0) + "'");
            bll.UpdateField("typename='板子厚度' and KeyName = '2.0'", "keyvalue = '" + _Convert.ToFloat(tbBoardThickness20.Text, 0) + "'");            

            //飞针测试
            bll.UpdateField("typename='飞针测试' and KeyName = '全部测试(样板及多层板免费测试)'", "keyvalue = '" + _Convert.ToFloat(tbTestType3.Text, 0) + "'");
            bll.UpdateField("typename='飞针测试' and KeyName = '抽测试(免费AOI光学扫描+飞针抽测)'", "keyvalue = '" + _Convert.ToFloat(tbTestType1.Text, 0) + "'");
            bll.UpdateField("typename='飞针测试' and KeyName = '不测试'", "keyvalue = '" + _Convert.ToFloat(tbTestType2.Text, 0) + "'"); 

            //焊盘喷镀
            bll.UpdateField("typename='焊盘喷镀' and KeyName = '有铅喷锡'", "keyvalue = '" + _Convert.ToFloat(tbPlatingType1.Text, 0) + "'");
            bll.UpdateField("typename='焊盘喷镀' and KeyName = '无铅喷锡'", "keyvalue = '" + _Convert.ToFloat(tbPlatingType2.Text, 0) + "'");
            bll.UpdateField("typename='焊盘喷镀' and KeyName = '沉金'", "keyvalue = '" + _Convert.ToFloat(tbPlatingType3.Text, 0) + "'"); 

            //交货时间
            bll.UpdateField("typename='交货时间' and KeyName = '样板24小时加急'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType1.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '样板48小时加急'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType2.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '多层板48小时加急'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType3.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '多层板72小时加急'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType4.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '多层板96小时加急'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType5.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '正常3-4天(样板)'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType6.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '正常4-5天(样板)'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType7.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '正常5-6天(样板)'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType8.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '正常6-7天(小批量)'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType9.Text, 0) + "'"); 
            bll.UpdateField("typename='交货时间' and KeyName = '正常7-8天(小批量)'", "keyvalue = '" + _Convert.ToFloat(tbDeliveryType10.Text, 0) + "'"); 

            //拼版款数
            bll.UpdateField("typename='拼版款数' and KeyName = '拼版款数'", "keyvalue = '" + _Convert.ToFloat(tbPinBanNum.Text, 0) + "'"); 

            //铜箔厚度
            bll.UpdateField("typename='铜箔厚度' and KeyName = '1/1oz'", "keyvalue = '" + _Convert.ToFloat(tbCopperThickness1.Text, 0) + "'");
            bll.UpdateField("typename='铜箔厚度' and KeyName = '2/2oz'", "keyvalue = '" + _Convert.ToFloat(tbCopperThickness2.Text, 0) + "'"); 

            //网络支付折扣
            bll.UpdateField("typename='网络支付折扣' and KeyName = '工程费'", "keyvalue = '" + _Convert.ToFloat(tbPay1.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '拼版费'", "keyvalue = '" + _Convert.ToFloat(tbPay2.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '板费'", "keyvalue = '" + _Convert.ToFloat(tbPay3.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '菲林费'", "keyvalue = '" + _Convert.ToFloat(tbPay4.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '税费'", "keyvalue = '" + _Convert.ToFloat(tbPay5.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '喷镀费'", "keyvalue = '" + _Convert.ToFloat(tbPay6.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '测试费'", "keyvalue = '" + _Convert.ToFloat(tbPay7.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '加急费'", "keyvalue = '" + _Convert.ToFloat(tbPay8.Text, 0) + "'");
            bll.UpdateField("typename='网络支付折扣' and KeyName = '颜色费'", "keyvalue = '" + _Convert.ToFloat(tbPay9.Text, 0) + "'"); 

            //需要发票
            bll.UpdateField("typename='需要发票' and KeyName = '不需要'", "keyvalue = '" + _Convert.ToFloat(tbBill1.Text, 0) + "'");
            bll.UpdateField("typename='需要发票' and KeyName = '普通发票'", "keyvalue = '" + _Convert.ToFloat(tbBill2.Text, 0) + "'");
            bll.UpdateField("typename='需要发票' and KeyName = '增值税发票'", "keyvalue = '" + _Convert.ToFloat(tbBill3.Text, 0) + "'");            

            //字符颜色
            bll.UpdateField("typename='字符颜色' and KeyName = '白色'", "keyvalue = '" + _Convert.ToFloat(tbFontColor1.Text, 0) + "'");
            bll.UpdateField("typename='字符颜色' and KeyName = '黑色'", "keyvalue = '" + _Convert.ToFloat(tbFontColor2.Text, 0) + "'"); 

            //阻焊覆盖
            bll.UpdateField("typename='阻焊覆盖' and KeyName = '过孔盖油'", "keyvalue = '" + _Convert.ToFloat(tbZhfg1.Text, 0) + "'");
            bll.UpdateField("typename='阻焊覆盖' and KeyName = '过孔开窗'", "keyvalue = '" + _Convert.ToFloat(tbZhfg2.Text, 0) + "'"); 
            
            //阻焊颜色
            bll.UpdateField("typename='阻焊颜色' and KeyName = '绿色'", "keyvalue = '" + _Convert.ToFloat(tbSolderColor1.Text, 0) + "'");
            bll.UpdateField("typename='阻焊颜色' and KeyName = '红色'", "keyvalue = '" + _Convert.ToFloat(tbSolderColor2.Text, 0) + "'");
            bll.UpdateField("typename='阻焊颜色' and KeyName = '黄色'", "keyvalue = '" + _Convert.ToFloat(tbSolderColor3.Text, 0) + "'");
            bll.UpdateField("typename='阻焊颜色' and KeyName = '蓝色'", "keyvalue = '" + _Convert.ToFloat(tbSolderColor4.Text, 0) + "'");
            bll.UpdateField("typename='阻焊颜色' and KeyName = '白色'", "keyvalue = '" + _Convert.ToFloat(tbSolderColor5.Text, 0) + "'");
            bll.UpdateField("typename='阻焊颜色' and KeyName = '黑色'", "keyvalue = '" + _Convert.ToFloat(tbSolderColor6.Text, 0) + "'"); 

            JscriptMsg("修改系统信息成功啦！", "option_list.aspx", "Success");                    
        }

    }
}